package com.sage.dao.model;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name="i_server")
//@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Server extends BeseEntity{
	
	
	private String name;
	
	@Column(name="pn_key")
	private String pnKey;
	
	private String descript;
	
	private String brand;
	
	private String cpu;
	
	private String memory;
	
	private String disk;
	
	private String addr;
	
	private int owner;
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, targetEntity=Company.class)
	@JoinColumn(name="server")
	private List<Company> companys;
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, targetEntity=ServerISP.class)
	@JoinColumn(name="server")
	private List<ServerISP> serverISPs;
	
	
	public List<ServerISP> getServerISPs() {
		return serverISPs;
	}

	public void setServerISPs(List<ServerISP> serverISPs) {
		this.serverISPs = serverISPs;
	}

	public List<Company> getCompanys() {
		return companys;
	}

	public void setCompanys(List<Company> companys) {
		this.companys = companys;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPnKey() {
		return pnKey;
	}

	public void setPnKey(String pnKey) {
		this.pnKey = pnKey;
	}

	public String getDescript() {
		return descript;
	}

	public void setDescript(String descript) {
		this.descript = descript;
	}

	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public String getCpu() {
		return cpu;
	}

	public void setCpu(String cpu) {
		this.cpu = cpu;
	}

	public String getMemory() {
		return memory;
	}

	public void setMemory(String memory) {
		this.memory = memory;
	}

	public String getDisk() {
		return disk;
	}

	public void setDisk(String disk) {
		this.disk = disk;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public int getOwner() {
		return owner;
	}

	
	/**
	 * 设置拥有者
	 * @param owner 拥有者, 0: 本公司所有, 1: 客户公司所有
	 */
	public void setOwner(int owner) {
		this.owner = owner;
	}
	
	
	
	/**
	 * 返回给定的电信网络营运商编号的服务器ISP信息
	 * @param pnKey
	 * @return
	 */
	public ServerISP getServerIspByKey(String pnKey){
		List<ServerISP> isps = getServerISPs();
		for(int i=0;i<isps.size();i++){
			ServerISP isp = isps.get(i);
			if(isp.getIsp().getPnKey().equals(pnKey)){
				return isp;
			}
		}
		return null;
	}
	
}
